package interfacesSIAB;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import administrador.gestion_de_clientes;
import administrador.gestion_de_proveedores;

public class IngresarProveedor extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JLabel email = null;
	private JTextField nombreProveedor = null;
	private JTextField telefonoProveedor = null;
	private JTextField direccionProveedor = null;
	private JTextField emailProveedor = null;
	private JButton AceptarProveedor = null;
	private JButton cancelar = null;
	private JTextField codEmpresa = null;
	private JLabel jLabel = null;

	/**
	 * This is the default constructor
	 */
	public IngresarProveedor() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(352, 424);
		this.setResizable(false);
		this.setContentPane(getJContentPane());
		this.setTitle("Ingresar Proveedor");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getAceptarProveedor(), null);
			jContentPane.add(getCancelar(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(20, 110, 136, 19));
			jLabel.setText("Codigo de la Empresa");
			email = new JLabel();
			email.setBounds(new Rectangle(100, 256, 37, 16));
			email.setText("  Email");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(80, 163, 60, 16));
			jLabel4.setText("  Direccion");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(83, 209, 55, 16));
			jLabel3.setText("  Telefono");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(10, 65, 147, 16));
			jLabel2.setText("  Nombre de la Empresa");
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(10, 28, 316, 302));
			jPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.orange), "Datos Proveedor", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel.add(jLabel2, null);
			jPanel.add(jLabel3, null);
			jPanel.add(jLabel4, null);
			jPanel.add(email, null);
			jPanel.add(getNombreProveedor(), null);
			jPanel.add(getTelefonoProveedor(), null);
			jPanel.add(getDireccionProveedor(), null);
			jPanel.add(getEmailProveedor(), null);
			jPanel.add(getCodEmpresa(), null);
			jPanel.add(jLabel, null);
		}
		return jPanel;
	}

	/**
	 * This method initializes nombreProveedor	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getNombreProveedor() {
		if (nombreProveedor == null) {
			nombreProveedor = new JTextField();
			nombreProveedor.setBounds(new Rectangle(181, 64, 117, 20));
		}
		return nombreProveedor;
	}

	/**
	 * This method initializes telefonoProveedor	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTelefonoProveedor() {
		if (telefonoProveedor == null) {
			telefonoProveedor = new JTextField();
			telefonoProveedor.setBounds(new Rectangle(184, 207, 115, 20));
		}
		return telefonoProveedor;
	}

	/**
	 * This method initializes direccionProveedor	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getDireccionProveedor() {
		if (direccionProveedor == null) {
			direccionProveedor = new JTextField();
			direccionProveedor.setBounds(new Rectangle(185, 166, 114, 20));
		}
		return direccionProveedor;
	}

	/**
	 * This method initializes emailProveedor	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getEmailProveedor() {
		if (emailProveedor == null) {
			emailProveedor = new JTextField();
			emailProveedor.setBounds(new Rectangle(182, 256, 115, 20));
		}
		return emailProveedor;
	}

	/**
	 * This method initializes AceptarProveedor	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getAceptarProveedor() {
		if (AceptarProveedor == null) {
			AceptarProveedor = new JButton();
			AceptarProveedor.setBounds(new Rectangle(51, 336, 85, 21));
			AceptarProveedor.setText("Guardar");
			AceptarProveedor.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				
				
					try {
						
						 
						
						
						if(getNombreProveedor().getText().trim().length() > 0 )
						{
							if(getCodEmpresa().getText().trim().length() > 0)
							{
								
								
																	
									gestion_de_proveedores agregar= new gestion_de_proveedores();
									agregar.agregarProveedor(getNombreProveedor().getText(),Integer.parseInt(getCodEmpresa().getText()),getDireccionProveedor().getText(),Integer.parseInt(getTelefonoProveedor().getText()),getEmailProveedor().getText());
									getNombreProveedor().setRequestFocusEnabled(true);
									getNombreProveedor().setText(" ");
									getCodEmpresa().setText("");
									getDireccionProveedor().setText("");
									getTelefonoProveedor().setText("");
									getEmailProveedor().setText("");
									JOptionPane.showMessageDialog(null,"El Proveedor fue Agregado al Sistema");
													
								
							}
							else{
								JOptionPane.showMessageDialog(null,"Por favor Debe de Ingresar el codigo de la Empresa");
							}
							
							
							
							
							
						}
						else{
							
							JOptionPane.showMessageDialog(null,"Por favor Debe de Ingresar el Nombre de la Empresa");
						}
						
						
						}
						catch (Exception e1) {
							JOptionPane.showMessageDialog(null,"El siguiente campo de datos  "+ e1.getMessage()+"  no corresponde al tipo del campo");
						    e1.printStackTrace();
						}
				
				
				
				}
			});
		}
		return AceptarProveedor;
	}

	/**
	 * This method initializes cancelar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCancelar() {
		if (cancelar == null) {
			cancelar = new JButton();
			cancelar.setBounds(new Rectangle(163, 336, 91, 23));
			cancelar.setText("Salir");
cancelar.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					
					dispose();
				}
			});
			
		
					
			
			
			
			
			
		}
		return cancelar;
	}

	/**
	 * This method initializes codEmpresa	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getCodEmpresa() {
		if (codEmpresa == null) {
			codEmpresa = new JTextField();
			codEmpresa.setBounds(new Rectangle(182, 113, 113, 19));
		}
		return codEmpresa;
	}

}  //  @jve:decl-index=0:visual-constraint="157,32"
